package com.cis.education.service.impl;

import java.util.List;

import com.cis.education.domain.EduCourse;
import com.cis.education.domain.EduCourseStudent;
import com.cis.education.mapper.EduCourseStudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.cis.education.mapper.EduStudentMapper;
import com.cis.education.domain.EduStudent;
import com.cis.education.service.IEduStudentService;
import com.cis.common.core.text.Convert;

/**
 * 学生档案管理Service业务层处理
 * 
 * @author 管理员
 * @date 2022-01-12
 */
@Service
public class EduStudentServiceImpl implements IEduStudentService 
{
    @Autowired
    private EduStudentMapper eduStudentMapper;

    @Autowired
    private EduCourseStudentMapper eduCourseStudentMapper;

    /**
     * 查询学生档案管理
     * 
     * @param id 学生档案管理主键
     * @return 学生档案管理
     */
    @Override
    public EduStudent selectEduStudentById(String id)
    {
        return eduStudentMapper.selectEduStudentById(id);
    }

    /**
     * 查询学生档案管理列表
     * 
     * @param eduStudent 学生档案管理
     * @return 学生档案管理
     */
    @Override
    public List<EduStudent> selectEduStudentList(EduStudent eduStudent)
    {
        return eduStudentMapper.selectEduStudentList(eduStudent);
    }

    /**
     * 新增学生档案管理
     * 
     * @param eduStudent 学生档案管理
     * @return 结果
     */
    @Override
    public int insertEduStudent(EduStudent eduStudent)
    {
        //添加选课信息
        if(!eduStudent.getCourseList().isEmpty()){
            for (Integer courseId : eduStudent.getCourseList()){
                EduCourseStudent eduCourseStudent = new EduCourseStudent();
                eduCourseStudent.setStudentId(eduStudent.getId());
                eduCourseStudent.setCourseId(courseId);
                eduCourseStudentMapper.insertEduCourseStudent(eduCourseStudent);
            }
        }
        return eduStudentMapper.insertEduStudent(eduStudent);
    }

    /**
     * 修改学生档案管理
     * 
     * @param eduStudent 学生档案管理
     * @return 结果
     */
    @Override
    public int updateEduStudent(EduStudent eduStudent)
    {
        //删除选课信息
        eduCourseStudentMapper.deleteEduCourseStudentByStudentId(eduStudent.getId());

        //添加选课信息
        if(!eduStudent.getCourseList().isEmpty() || eduStudent.getCourseList() != null){
            for (Integer courseId : eduStudent.getCourseList()){
                EduCourseStudent eduCourseStudent = new EduCourseStudent();
                eduCourseStudent.setStudentId(eduStudent.getId());
                eduCourseStudent.setCourseId(courseId);
                eduCourseStudentMapper.insertEduCourseStudent(eduCourseStudent);
            }
        }
        return eduStudentMapper.updateEduStudent(eduStudent);
    }

    /**
     * 批量删除学生档案管理
     * 
     * @param ids 需要删除的学生档案管理主键
     * @return 结果
     */
    @Override
    public int deleteEduStudentByIds(String ids)
    {
        return eduStudentMapper.deleteEduStudentByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除学生档案管理信息
     * 
     * @param id 学生档案管理主键
     * @return 结果
     */
    @Override
    public int deleteEduStudentById(String id)
    {
        return eduStudentMapper.deleteEduStudentById(id);
    }
}
